﻿@model BookStore.Helpers.PagedList<BookStore.Models.Order>

@{
    ViewBag.Title = "订单管理_管理员后台_第三波书店";
    Layout = "~/Areas/Admin/Views/Shared/_AdminLayout.cshtml";
}
@section styles{
    <style type="text/css">
        .data_table {
            border-collapse:collapse;
        }
        .cartImg {
            text-align:center;
        }
    </style>
}

<div style="margin-left:5%;">
<h3 style="line-height:30px;">您现在的位置：
        @Html.ActionLink("第三波","Index","../Home")&gt;
        @Html.ActionLink("管理员后台","Index","Home")&gt;
        @Html.ActionLink("订单管理","Index","Order")
</h3>
<table class="data_table" cellspacing="3" cellpadding="0"  border="1" style="border-width: 0px; width: 96%;">
    <tr style="height:30px;">
        <th width="10%">图示</th>
        <th width="66%">书名</th>
        <th width="6%">数量</th>
        <th width="8%">单价</th>
        <th width="10%">操作</th>
    </tr>
    @{
        decimal orderTotalPrices = 0;    
    }
    @foreach (var o in Model)
    {
        <tr style="background-color:#bdeee7;height:25px;">
            <td colspan="3" width="90%">
                &nbsp;订单编号:@o.Id &nbsp;&nbsp;
                买家账号:@o.UserInfo.LoginId &nbsp;&nbsp;
                订单日期:@o.OrderDate.ToString("yyyy年MM月dd日hh时mm分ss秒") &nbsp;&nbsp;
                订单金额:￥@o.TotalPrice.ToString("f2")<td>
            <td  width="10%" style="text-align:center;">
                @Html.ActionLink("删除订单", "DeleteOrder", "Order", new { id = o.Id }, new { onclick="return confirm('确定要删除这个订单吗么？');"})</td>
        </tr>
        foreach (var od in o.OrderDetails)
        {
            <tr class="cartImg">
                <td><a href="@Url.Action("Detail", "Book", new { id = od.Book.Id })"><img src="@Url.Content("~/Images/BookCovers/"+@od.Book.ISBN+".jpg")" title="@od.Book.Title" width="80" height="100"/></a></td>
                <td>@Html.ActionLink(od.Book.Title, "Detail", "Book", new { id = od.Book.Id }, new { title=od.Book.Title})</td>
                <td>@od.Quantity</td>
                <td>@od.UnitPrice.ToString("c")</td>
                <td>@Html.ActionLink("删除", "DeleteOrderDetail", "Order", new { id = od.Id }, new { onclick="return confirm('确定要删除这个子订单吗么？');"})</td>
            </tr>
        }
        if (o.OrderDetails.Count == 0)
        {
             <tr>
                 <td colspan="5" height="35px">
                      商品已删除。
                 </td>
            </tr>
        }
        orderTotalPrices += o.TotalPrice;        
    }
    @if ( Model.Count==0)
    {
         <tr>
             <td colspan="5" height="50px">
                 <a target="_blank" href="http://www.baidu.com">还没有用户订过订单记录，快去推广您的网站吧。</a>
             </td>
        </tr>
    }
    else
    {
        <tr>
            <td colspan="3" align="right">
                所有订单总金额：<em><strong>￥@ViewBag.TotalMoneys.ToString("f2")&nbsp;&nbsp;</strong></em>&nbsp;&nbsp; 
                本页订单总金额：<em><strong id="cartTotal">￥@orderTotalPrices.ToString("f2")&nbsp;&nbsp;</strong></em>
            </td>
            <td align="center" colspan="2">
                @using (Html.BeginForm("EmptyOrderAll", "Order", FormMethod.Post, new { onsubmit = "return confirm('确定要删除所有订单记录吗？请慎重考虑！！！');" })) 
                {
                    <input type="submit" value="清空所有订单"/>
                }              
            </td>
        </tr>
    }
</table>
@if (Model.Count>0)
{
    <div class="pager">
        @Html.Pager(Model)
    </div>
}
</div>